package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.constant.Result;
import com.hl.sfzy.entity.SysCourseFavorites;
import com.hl.sfzy.entity.SysUser;
import com.hl.sfzy.service.SysCourseFavoritesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author ffc
 * @version 1.0
 * @description: TODO
 * @className: SysCourseFavoritesController
 * @date 2024/7/13 10:18
 */

@RestController
public class SysCourseFavoritesController {
    @Autowired
    private SysCourseFavoritesService cfs;

    /*增加收藏*/
    @PostMapping("/sysCourseFavorites")
    public Result add(@RequestBody SysCourseFavorites entity){
        return cfs.add(entity)>0?Result.success():Result.error();
    }

    /*根据id删除*/
    @DeleteMapping("/sysCourseFavorites/{id}")
    public Result remove(@PathVariable("id") Integer id){
        return cfs.remove(id)>0?Result.success():Result.error();
    }

    /*根据id批量删除*/
    @DeleteMapping("/sysCourseFavorites")
    public Result removeBatch(Integer[] ids){
        return cfs.removeBatch(ids)>0?Result.success():Result.error();
    }

    /*根据条件查询所有*/
    @GetMapping("/sysCourseFavorites")
    public Result find(SysCourseFavorites entity){
        List<SysCourseFavorites> list = cfs.find(entity);
        return Result.success(list);
    }

    /*根据id查询所有*/
    @GetMapping("/sysCourseFavorites/{id}")
    public Result findById(@PathVariable Integer id){
        SysCourseFavorites entity = cfs.findById(id);
        return Result.success(entity);
    }

    /*分页查询所有*/
    @GetMapping("/sysCourseFavorites/page")
    public Result findPage(
            @RequestParam(value = CommonConstant.PAGE_NUM,required = false,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(value = CommonConstant.PAGE_SIZE,required = false,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            SysCourseFavorites entity){
        Map<String, Object> map = cfs.findPage(pageNum, pageSize, entity);
        return Result.success(map);
    }

    /*分页查询支付和未支付所有*/
    @GetMapping("/sysCourseFavorites/status")
    public Result findPage(
            @RequestParam(value = CommonConstant.PAGE_NUM,required = false,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(value = CommonConstant.PAGE_SIZE,required = false,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            Integer status,SysCourseFavorites entity){
        Map<String, Object> map = cfs.findStatus(pageNum, pageSize,status,entity);
        return Result.success(map);
    }
}
